/**
 * @author Jeff Denton
 */
function login() {
	var userName = $('userid').value;
	var password = $('password').value;
	x_login(userName,password,returnLogin);
}

function returnLogin(string) {
	var stringArray = string.split('|');
	var error   = stringArray[0];
	var message = stringArray[1];
	
	if (error == 1) {
		$('messageContainer').innerHTML = message;
		$('messageContainer').className = 'errorMessage';
	} else {
		// Set cookies
		var uID      = stringArray[2];
		var fullName = stringArray[3];
		var logged   = stringArray[4];
		
		cookieSet('UID',uID);
		cookieSet('userFullName',fullName);
		cookieSet('logged',logged); 
		
		// Render desktop
		showDesktop();				
				
		// Close login window
		LoginWindow.closeWindow();
	}
}

function logout() {
	x_logout(returnLogout);
}

function returnLogout() {
	// Clear cookies
	cookieDelete('UID');
	cookieDelete('userFullName');
	cookieDelete('logged'); 
	// Hide desktop
	hideDesktop(1);
	
	// Popup login window again
	LoginWindow.createWindow();
}